yjx.controller('msgController',['$rootScope','$scope','$timeout','$fetch','modalService',function($rootScope,$scope,$timeout,$fetch,modalService){
    $rootScope.tabCtrlName = $rootScope.tabCtrlNameArr[3];
    var params = {
        limit: 20,
        offset: 1,
        userId:$rootScope.userId
    }
    $scope.pageNum = 1;
    $scope.hideShows = true;
    if($rootScope.userId){
        getMsgList();
    }
    function getMsgList(){
        $fetch.fetch(
            '/message/me',
            {
                params:params,
                cache:false
            }

        ).then(function(data){
                $timeout(function(){
                    if(data){
                        $scope.paging = data.pages;
                        $scope.msgList = data.rows;
                        //更新状态、数据加载控制
                        $scope._updated = 'reupdated';
                        $scope.hideShows = false;
                    }
                })
            }).catch(function(e){
                modalService.mainMsgError(e.msg);
            })
    }

    /*翻页*/
    $scope.list = function(){
        params.offset = $scope.pageNum;
        $fetch.fetch(
            '/message/me',
            {
                params:params,
                cache:false
            }
        ).then(function(data){
                $timeout(function(){
                    if(data){
                        $scope.paging = data.pages;
                        $scope.msgList = $scope.msgList.concat(data.rows);
                        //更新状态、数据加载控制
                        $scope._updated = 'reupdated';
                        $scope.hideShows = false;
                    }
                })
            }).catch(function(e){
                modalService.mainMsgError(e.msg);
            })
    }


    /*拒绝申请*/
    $scope.msgAct = function(msgId,meberId,status){
            $fetch.fetch(
                '/group/join/deal',
                {
                    params:{
                        messageId:msgId,
                        groupMemberId:meberId,
                        userId:$rootScope.userId,
                        status:status
                    },
                    cache:false,
                    type:'POST'
                }
            ).then(function(data){
                }).catch(function(e){
                    modalService.mainMsgError(e.msg);
                })
    }
}])